package com.rocketmq.config;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ytj
 * @date 2024/10/11 9:37
 */
@Configuration
public class RocketMqConfig {

    /**
     * 广播模式发送者
     * */
    @Bean
    public RocketMQTemplate broadcastTemplate(){
        RocketMQTemplate rocketMQTemplate=new RocketMQTemplate();
        DefaultMQProducer defaultMQProducer=new DefaultMQProducer();
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        defaultMQProducer.setProducerGroup("boot-product-broadcast");
        rocketMQTemplate.setProducer(defaultMQProducer);
        return rocketMQTemplate;
    }

    /**
     * 普通模式发送者
     * */
    @Bean
    public RocketMQTemplate template(){
        RocketMQTemplate rocketMQTemplate=new RocketMQTemplate();
        DefaultMQProducer defaultMQProducer=new DefaultMQProducer();
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        defaultMQProducer.setProducerGroup("boot-product");
        rocketMQTemplate.setProducer(defaultMQProducer);
        return rocketMQTemplate;
    }

    /**
     * 顺序模式发送者
     * */
    @Bean
    public RocketMQTemplate orderTemplate(){
        RocketMQTemplate rocketMQTemplate=new RocketMQTemplate();
        DefaultMQProducer defaultMQProducer=new DefaultMQProducer();
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        defaultMQProducer.setProducerGroup("order-product");
        rocketMQTemplate.setProducer(defaultMQProducer);
        return rocketMQTemplate;
    }

    /**
     * 延时消息
     * */
    @Bean
    public RocketMQTemplate delayTemplate(){
        RocketMQTemplate rocketMQTemplate=new RocketMQTemplate();
        DefaultMQProducer defaultMQProducer=new DefaultMQProducer();
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        defaultMQProducer.setProducerGroup("delay-product");
        rocketMQTemplate.setProducer(defaultMQProducer);
        return rocketMQTemplate;
    }

    /**
     * tag过滤消息
     * */
    @Bean
    public RocketMQTemplate tagTemplate(){
        RocketMQTemplate rocketMQTemplate=new RocketMQTemplate();
        DefaultMQProducer defaultMQProducer=new DefaultMQProducer();
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        defaultMQProducer.setProducerGroup("tag-product");
        rocketMQTemplate.setProducer(defaultMQProducer);
        return rocketMQTemplate;
    }


}
